<template>
  <div class="right">
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 权限表格 -->
    <!-- 固定表头 -->
    <el-table
      height="600"
      v-loading="loading"
      class="mt-15 mb-15"
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        type="index"
        width="50">
      </el-table-column>
      <el-table-column
        prop="authName"
        label="权限名称">
      </el-table-column>
      <el-table-column
        prop="path"
        label="路径">
      </el-table-column>
      <el-table-column
        label="层级">
        <!-- 此处写法改成插槽 ,目的是为了能够使用过滤器  -->
        <template slot-scope="scope">
          <!-- <span>{{scope.row.level | fmtLevel}}</span> -->
          <el-tag v-if="scope.row.level==='0'">一级</el-tag>
          <el-tag type="success" v-if="scope.row.level==='1'">二级</el-tag>
          <el-tag type="danger" v-if="scope.row.level==='2'">三级</el-tag>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getRights } from '@/api'
export default {
  data () {
    return {
      loading: false,
      tableData: []
    }
  },
  // 创建局部过滤器
  filters: {
    fmtLevel: function (level) {
      switch (level) {
        case '0':
          return '一级'
        case '1':
          return '二级'
        default:
          return '二级'
      }
    }
  },
  mounted () {
    this.initTable()
  },
  methods: {
    initTable () {
      this.loading = true
      getRights('list').then(res => {
        // console.log(res)
        if (res.data.meta.status === 200) {
          this.tableData = res.data.data
          this.loading = false
          this.$message.success(res.data.meta.msg)
        } else {
          this.$message.error(res.data.meta.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
